<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/js/bootstrap/bootstrap3/css/bootstrap.css">
    <link rel="stylesheet" href="/js/bootstrap/bootstrap3/css/bootstrap-theme.css">

    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap/bootstrap3/js/bootstrap.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootstrap-table/bootstrap-table.css">
    <script type="text/javascript" src="/js/bootstrap/bootstrap-table/bootstrap-table.js"></script>
    <script type="text/javascript" src="/js/bootstrap/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css">
    <script type="text/javascript" src="/js/bootstrap/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="/js/bootstrap/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>

    <script type="text/javascript" src="/js/bootstrap/bootstrap-bootbox/bootbox.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootStrap-addTabs/bootstrap.addtabs.css">
    <script type="text/javascript" src="/js/bootstrap/bootStrap-addTabs/bootstrap.addtabs.min.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootstrap-treeview/bootstrap-treeview.min.css">
    <script type="text/javascript" src="/js/bootstrap/bootstrap-treeview/bootstrap-treeview.min.js"></script>

    <link rel="stylesheet" href="/js/bootstrap/bootstrap-fileinput/css/fileinput.css">
    <script type="text/javascript" src="/js/bootstrap/bootstrap-fileinput/js/fileinput.js"></script>
    <script type="text/javascript" src="/js/bootstrap/bootstrap-fileinput/js/locales/zh.js"></script>
</head>
<body>
<!-- 登录表单 -->
<form style="margin-left:500px;margin-top:200px;">
    <div class="form-group">
        <label for="name" stype="display:inline;">账户：</label>
        <input type="text" class="form-control" id="name" style="display:inline;width:200px;"autocomplete="off" />
    </div>
    <div class="form-group">
        <label for="password" style="display:inline;">密码：</label>
        <input type="text" class="form-control" id="password" style="display:inline;width:200px;"autocomplete="off" />
    </div>
    <button type="button" class="btn btn-primary" onclick="login()">登录</button>
    <button type="button" class="btn btn-primary" onclick="register()">注册</button>
</form>
</body>
<script type="text/javascript">

    //登录
    function login(){
        var name = $("#name").val();
        var password = $("#password").val();
        $.ajax({
            url:"loginUser",
            data:{
                "name":name,
                "password":password
            },
            success:function(data){
                alert(data.message);
                //登录成功，跳转到主页面
                if(data.message=="登录成功！！！"){
                    sess(name);
                    location.href="index";
                }
            }
        });
    }
    function sess(name) {
        alert(name);
        $.ajax({
            url:"SessUser",
            data:{
                "name":name
            },
            success:function(){

            }
        });
    }
    var res;
    function createAddContent(url){
        $.ajax({
            url:url,
            async:false,//同步
            success:function(data){
                res = data;
            }
        });
        return res;
    }
    function register(){
        bootbox.dialog({
            title:'注册',
            message: createAddContent("toAddUser"),//弹出框的内容 能够识别html标签
            closeButton: true,//是否显示关闭按钮
            buttons : {
                "success" : {
                    "label" : "<i class='icon-ok'></i> 保存",
                    "className" : "btn-sm btn-success",
                    "callback" : function() {
                        if ($("#password1").val()==null || $("#password1").val()==""){
                            alert("密码不能为空");
                        } else
                        if ($("#passwordq").val()==null || $("#passwordq").val()==""){
                            alert("确认密码不能为空");
                        } else
                        if ($("#passwordq").val()!=$("#password1").val()){
                            alert("两次密码不一致");
                        } else  {
                            $.ajax({
                                url:'addUser',
                                type:'post',
                                data:$("#addOrder").serialize(),
                                //dataType:'json',
                                success:function(data){
                                    bootbox.alert({
                                        size: "small",
                                        title: "提示",
                                        message: "新增数据成功"
                                    })
                                }
                            });
                        }
                    }
                },
                "cancel" : {
                    "label" : "<i class='icon-info'></i> 取消",
                    "className" : "btn-sm btn-danger",
                    "callback" : function() {

                    }
                }
            }

        });
    }
</script>
</html>